﻿Public Class Login
    Dim dt As New DataTable
    Dim ja As Int16
    Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dt = cmd.ExcecuteDatatable("SELECT * FROM [USER]")
    End Sub

    Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
        Dim frm = MainMenu
        If ja > 5 Then
            MessageBox.Show("អ្នកបញ្ចូលឈ្មោះអ្នកប្រើប្រាស់និងលេខសំងាត់ខុស៥ដងប្រពន្ធ័ត្រូវបិទ")
            Me.Close()
        End If
        ja += 1
        If txtuser.Text = "" Or txtpwd.Text = "" Then
            MessageBox.Show("Please input username and password")
            Exit Sub
        Else
            Dim mes As String
            For i = 0 To dt.Rows.Count - 1
                If LCase(dt.Rows(i).Item(1)) = LCase(txtuser.Text) And dt.Rows(i).Item(2) = txtpwd.Text Then
                    If dt.Rows(i).Item(3) = 1 Then
                        MainMenu.per = 1
                    End If
                    frm.Show()
                    Me.Close()
                    mes = "ចូលប្រពន្ធ័បានសម្រេច"
                End If
            Next
            If mes <> "" Then
                'MessageBox.Show(mes)
            Else
                MessageBox.Show("ចូលប្រពន្ធ័មិនបានសម្រេច")
            End If
        End If
    End Sub

    Private Sub txtpwd_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpwd.Enter
        ' btnok_Click(sender, e)
    End Sub

    Private Sub txtpwd_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtpwd.KeyDown
        'btnok_Click(sender, e)
        If e.KeyCode = Keys.Enter Then
            e.SuppressKeyPress = True
            btnok_Click(sender, e)
        End If

    End Sub

    Private Sub txtpwd_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtpwd.KeyUp
        'btnok_Click(sender, e)
    End Sub

    Private Sub txtuser_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtuser.KeyDown
        If e.KeyCode = Keys.Enter Then
            e.SuppressKeyPress = True
            btnok_Click(sender, e)
        End If
    End Sub
End Class